package com.tansun.easycare.rule.rulemange.model;

import java.text.DecimalFormat;

import com.alibaba.druid.util.StringUtils;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.rulemange.entity.RuleManage;

public class RuleManageBO extends RuleManage {

    /**
     *
     */
    private static final long serialVersionUID = -9116429523995264082L;
    /**
     * 授权人;
     */
    private String users;
    /**
     * 锁定人
     */
    private String locker;
    /**
     * 所有人
     */
    private String owner;

    public String getUsers() {
        return users;
    }

    public void setUsers(String users) {
        this.users = users;
    }

    public String getLocker() {
        return locker;
    }

    public void setLocker(String locker) {
        this.locker = locker;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    /**
     * 初始化改条记录的修改内容
     */
    public void InitModifiedContent(RuleManage base) throws BizException {
        if (!StringUtils.isEmpty(base.getStatus()))
            this.setStatus(base.getStatus());
        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        if ("2".equals(base.getStatus())) //发布
        {
            String verStr = this.getVersion().substring(1, this.getVersion().length() - 3);
            float version = Float.parseFloat(verStr);
            if (this.getVersion().matches("v\\d+\\.00")) {
                throw new BizException("E-000200");
            }
            version = version + 1;
            this.setVersion("v" + decimalFormat.format(version));
        } else if ("1".equals(base.getStatus())) //修改
        {
            String verStr = this.getVersion().substring(1, this.getVersion().length());
            float version = Float.parseFloat(verStr);
            version = (float) (version + 0.01);
            this.setVersion("v" + decimalFormat.format(version));
        }
    }
}
